/* -----------------------------------------------------------------------
 * Include the following lines in your makefile:
 *
 * unittest1: cardtest2.c dominion.o rngs.o
 *      gcc -o cardtest2 -g  cardtest2.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

#define PLAY_CARD village
#define PLAY_CARD_STR "village"

int main() {
    int r, handCount, handPos = 0, choice1 = 0, choice2 = 0, choice3 = 0;
    int numPlayer = 2;
    int seed = 1000;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    int deckCount = 5;
    int cardChange = 1;
    int actionChange = 2;
    int player_hand[maxHandCount];
    int preDeckCount, preHandCount, preActions;
    int postDeckCount, postHandCount, postActions;

	player_hand[0] = PLAY_CARD;
	player_hand[1] = copper;
	player_hand[2] = copper;
	player_hand[3] = estate;
	player_hand[4] = estate;

#if (NOISY_TEST == 1)    		
    printf ("TESTING %s card:\n", PLAY_CARD_STR);	
#endif

	for (handCount = 1; handCount <= maxHandCount; handCount++)
    {
#if (NOISY_TEST == 1)
		printf("Test player with card hand count of %d.\n",handCount);
#endif
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
	    r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
		G.handCount[0] = handCount;                 // set the number of cards on hand
		memcpy(G.hand[0], player_hand, sizeof(int) * handCount); // set all the cards to player_hand
		preDeckCount = G.deckCount[0];
		preHandCount = G.handCount[0];
		preActions = G.numActions;
		
		// play the card in position 0
		r = playCard(handPos,choice1,choice2,choice3,&G);
		postDeckCount = G.deckCount[0];
		postHandCount = G.handCount[0];
		postActions = G.numActions;		

#if (NOISY_TEST == 1)
        printf("Pre deck count = %d, Post deck count = %d, expected = %d.\n", preDeckCount, postDeckCount, deckCount - cardChange);
        printf("Pre hand count = %d, Post hand count = %d, expected = %d.\n", preHandCount, postHandCount, handCount -1 + cardChange);
        printf("Pre actions = %d, Post actions = %d, expected = %d.\n", preActions, postActions, preActions + actionChange - 1);
#endif					
		
		assert(postDeckCount == deckCount - cardChange);
		assert(postHandCount == handCount -1 + cardChange);
		assert(postActions == preActions + actionChange - 1);
		
	}
    
    printf("All domain tests passed!\n");
        
    return 0;
}
